/**
 * 初始化部门详情对话框
 */
var DoctorLookedInfoDlg = {
    doctorLookedInfoData: {},
    zTreeInstance: null,
    validateFields: {}
};

/**
 * 清除数据
 */
DoctorLookedInfoDlg.clearData = function () {
    this.doctorLookedInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
DoctorLookedInfoDlg.set = function (key, val) {
    this.doctorLookedInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
DoctorLookedInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
DoctorLookedInfoDlg.close = function () {
    // parent.layer.close(window.parent.Reservations.layerIndex);
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}


/**
 * 显示部门选择的树
 *
 * @returns
 */
DoctorLookedInfoDlg.showReservationsSelectTree = function () {
    var pName = $("#pName");
    var pNameOffset = $("#pName").offset();
    $("#parentReservationsMenu").css({
        left: pNameOffset.left + "px",
        top: pNameOffset.top + pName.outerHeight() + "px"
    }).slideDown("fast");

    $("body").bind("mousedown", onBodyDown);
}

/**
 * 隐藏部门选择的树
 */
DoctorLookedInfoDlg.hideReservationsSelectTree = function () {
    $("#parentReservationsMenu").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发，不用弹起
};

/**
 * 收集数据
 */
DoctorLookedInfoDlg.collectData = function () {
    this.set('id').set('jiedaiContent').set('revisitTime').set('doctor').set('remarks').set('revisitContent');
}

/**
 * 验证数据是否为空
 */
DoctorLookedInfoDlg.validate = function () {
    $('#doctorLookedInfoForm').data("bootstrapValidator").resetForm();
    $('#doctorLookedInfoForm').bootstrapValidator('validate');
    return $("#doctorLookedInfoForm").data('bootstrapValidator').isValid();
};

DoctorLookedInfoDlg.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
};

/**
 * 新增随访
 */
DoctorLookedInfoDlg.submit = function () {
    this.clearData();
    this.collectData();
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/doctorLooked/",function (data) {
        Feng.success("编辑成功!");
        window.parent.DoctorLooked.table.refresh();
        DoctorLookedInfoDlg.close();
    },function (data) {
        Feng.error("编辑失败!请联系管理员" + data.responseJSON.message + "!");
    })
    ajax.set(this.doctorLookedInfoData);
    ajax.start();
}
/**
 * 提交修改
 */
// DoctorLookedInfoDlg.toComment = function () {
//     this.clearData();
//     this.collectData();
//     var status = $('#status').val();
//     if (!this.validate()) {
//         return;
//     }
//     //提交信息
//     var ajax = new $ax(Feng.ctxPath + "/doctorLooked/doctorComment", function (data) {
//             Feng.success("点评成功!");
//             window.parent.DoctorLooked.table.refresh();
//             DoctorLookedInfoDlg.close();
//     }, function (data) {
//         Feng.error("点评失败!请联系管理员" + data.responseJSON.message + "!");
//     });
//     ajax.set(this.doctorLookedInfoData);
//     ajax.start();
// }


function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "parentReservationsMenu" || $(
            event.target).parents("#parentReservationsMenu").length > 0)) {
        DoctorLookedInfoDlg.hideReservationsSelectTree();
    }
}

function appointment() {
    var reservationsId = document.getElementById("reservationsId").value;
    var customerId = document.getElementById("customerId").value;
    var doctor = document.getElementById("userName").value;
    var cid = customerId + "," + reservationsId + "," + doctor;
    var index = layer.open({
        type: 2,
        title: '复诊预约',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_appointment/' + cid
    });
    this.layerIndex = index;
}

$(function () {
    $.ajax({
        url: Feng.ctxPath + "/consultant/getDoctor",
        type: "get",
        success: function (data) {
            var txt = '<option value="">--请选择医生--</option>';
            for (var i = 0; i < data.length; i++) {
                txt += '<option value="' + data[i].doctor + '">' + data[i].doctor + '</option>';
            }
            document.getElementById('doctor').innerHTML = txt;
            //状态单选
            var seleteDoctorValue = $('#doctorValue').val();
            if (seleteDoctorValue != "") {
                $("#doctor option[value=" + seleteDoctorValue + "]").attr("selected", "selected");
            }
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
    Feng.initValidator("doctorLookedInfoForm", DoctorLookedInfoDlg.validateFields);
    $("#followResults").click(function () {
        $("#revisitContent").val("洁牙后暂无不适")
    });
    $("#currency").click(function () {
        var s = $("#remarks").val();
        $("#remarks").val(s+"如有疼痛或不舒服，请拔打诊所电话。")
        $("#remarks2").val("如有疼痛或不舒服，请拔打诊所电话。")
    });
    $("#scaling").click(function () {
        var s = $("#remarks").val();
        $("#remarks").val(s+"洁牙以后一天回访")
        $("#remarks2").val("洁牙以后一天回访")
    });
    $("#threeFollow").click(function () {
        var s = $("#remarks").val();
        $("#remarks").val(s+"三个月随访")
        $("#remarks2").val("三个月随访")
    });
    $("#yearFollow").click(function () {
        var s = $("#remarks").val();
        $("#remarks").val(s+"复诊一年后洁牙")
        $("#remarks2").val("复诊一年后洁牙")
    });
});
